package com.docker.log;

import com.jfinal.aop.Inject;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;
import com.docker.core.mvc.service.BaseService;

public class LogService extends BaseService {

    @Inject
    private LogDao logDao;

    public boolean save(String tableName, Record log, boolean isSave) {
        saveReturnId(tableName, log, isSave);
        log.remove("log_id");
        return true;
    }

    public String saveReturnId(String tableName, Record log, boolean isSave) {
        log.set("log_id", getUUID32());
        if (!isSave && StrKit.notBlank(log.getStr("update_time"))) {
            log.set("create_time", log.getStr("update_time"));
        }
        if (!isSave && StrKit.notBlank(log.getStr("update_oper_id"))) {
            log.set("create_oper_id", log.getStr("update_oper_id"));
        }
        log.remove("update_time", "update_oper_id");
        logDao.save(tableName, log);
        return log.getStr("log_id");
    }

}
